import React, { Component } from 'react'
import { TabBar } from 'antd-mobile'  // tabbar组件
import PropTypes from 'prop-types'
import { withRouter } from 'react-router-dom' // 包装组件，让非路由组件能访问路由属性

// 获取TabBar的 item组件
const Item = TabBar.Item

class NavFooter extends Component {
  // 限制和规定父组件传入的props
  static propTypes = {
    navList: PropTypes.array.isRequired,  // nav列表
    unReadMsgCount: PropTypes.number.isRequired, // 未读数量
  }
  
  render () {
    const {navList, unReadMsgCount} = this.props
    const {pathname} = this.props.location
    return (
      <div>
        {/*TabBar组件 遍历navList 生成item*/}
        <TabBar>
          {navList.map((value, index) => (
            //  Item是底部图标组件 需要传递参数
            //  badge显示未读数量
            <Item
              key={index}
              badge={value.path === '/message' ? unReadMsgCount : null}
              title={value.text}
              icon={{uri: `/images/nav/${value.icon}.png`}}
              selectedIcon={{uri: `/images/nav/${value.icon}-selected.png`}}
              selected={pathname === value.path}
              onPress={() => this.props.history.replace(value.path)}
            
            >
            
            </Item>
          
          ))}
        </TabBar>
      </div>
    )
  }
}

export default withRouter(NavFooter) // 返回路由包装后的组件